<?php
	//Requiere ConfigManager.php
	require_once "config_manager.php";
	
	class DAO
	{
		private static $config;
		
		private static function connect_to_db()
		{
			$config = ConfigManager::getInstance();
			$server = self::$config->get_mysql_server();
			$user = self::$config->get_mysql_user();
			$password = self::$config->get_mysql_password();
			$catalog = self::$config->get_mysql_catalog();
			
			$connection = mysql_connect($server, $user, $password);
			
			if(!$connection)
			{
				throw new Exception('Could not connect to DB.');
			}
			
			mysql_select_db($catalog, $connection);
			
			return $connection;
		}
		
		private static function close_connection($connection)
		{
			mysql_close($connection);
		}
		
		public static function run_query($strQuery)
		{
			try
			{
				$connection = self::connect_to_db();
				
				$result = mysql_query($strQuery);
			
				self::close_connection($connection);
				
				return $result;
			} catch(Exception $e)
			{
				echo 'Caught exception: ', $e->getMessage(), "\n";
			}
		}
	}
?>